#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define ROW 1000
#define COL 1000

void init(int **tab) {
	int i, j;
	for(i = 0; i < ROW; i++) {
		*(tab + i) = (int*)malloc(COL * sizeof(int));
	}
}
void tab_init(int **tab, int *tab_size, int *tab_elements) {
	int i, j;
	//for(i = 0; i < ROW; i++) {
		//tab_size[i] = 0;
		memset(tab_size, 0, ROW * sizeof(int));
		//tab_elements[i] = 0;
		/*
		for(j = 0; j < COL; j++) {
			*(*(tab + i) + j) = 0;
		}
		*/
	//}
}

void tab_add(int a, int b, int **tab, int *tab_elements) {
	*(tab[a] + tab_elements[a]) = b;
	tab_elements[a]++;
	*(tab[b] + tab_elements[b]) = a;
	tab_elements[b]++;
}

void tab_print(int **tab, int *tab_elements) {
	int i, j;
	for(i = 0; i < ROW; i++) {
		if(tab_elements[i] > 0) {
			printf("[%03d] ", i);
			for(j = 0; j < tab_elements[i]; j++) {
				printf("%d ", *(tab[i] + j));
			}
			printf("\n");
		}
	}
}

void tab_size_print(int *tab_size) {
	int i;
	for(i = 0; i < ROW; i++) {
		if(tab_size[i] > 0)
			printf("[%03d]%d\n", i, tab_size[i]);
	}
}

void getSize(int element, int elementFrom, int **tab, int *tab_size, int *tab_elements) {
	int i;
	if(tab_elements[element] == 1 && element != 0) {
		tab_size[element] = 1;
		return;
	}
	for(i = 0; i < tab_elements[element]; i++) {
		if(*(tab[element] + i) != elementFrom) {
			getSize(*(tab[element] + i), element, tab, tab_size, tab_elements);
			tab_size[element] += tab_size[*(tab[element] + i)]  + 1;
		}
	}
	tab_size[element]++;
}

int getSum(int *tab_size) {
	int i, sum = 0;
	for(i = 0; i < ROW; i++)
		sum += tab_size[i];
	return sum;
}

int tab[ROW][COL];

int main() {
	int T, N, a, b, i;
	int  tab_size[ROW], tab_elements[ROW];
	
	init(tab);
	scanf("%d", &T);
	while(T--) {
		memset(tab_size, 0, ROW * sizeof(int));
		memset(tab_elements, 0, ROW * sizeof(int));
		scanf("%d", &N);
		for(i = 0; i < N - 1; i++) {
			scanf("%d %d", &a, &b);
			*(tab[a] + tab_elements[a]++) = b;
			*(tab[b] + tab_elements[b]++) = a;
		}
		getSize(0, 0, tab, tab_size, tab_elements);
		printf("%d\n", getSum(tab_size));		
	}	
	
	return 0;
}
